package com.woniuxy.movice.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.woniuxy.movice.dto.Page;
import com.woniuxy.movice.entity.Movie;

public interface MovieMapper {

	@Select("select count(*) from movie where mshow=0")
	int findMovieNum();

	@Select("select * from movie where mshow=0 limit #{index},#{count}")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mname", property = "mname"),
		@Result(column = "director", property = "director"), @Result(column = "mtype", property = "mtype"),
		@Result(column = "mstar", property = "mstar"), @Result(column = "mlength", property = "mlength"),
		@Result(column = "mcomment", property = "mcomment"),@Result(column = "location", property = "location"),
		@Result(column = "mmassage", property = "mmassage"), 
		@Result(column = "id", property = "movieImgs", many = @Many(select = "com.woniuxy.movice.mapper.MovieImgMapper.findMovieImgByMid")) })
	List<Movie> findMovieByPage(Page<Movie> page);
	
	@Select("select * from movie where mshow=0 and mtype like #{mtype} limit #{index},#{count}")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mname", property = "mname"),
		@Result(column = "director", property = "director"), @Result(column = "mtype", property = "mtype"),
		@Result(column = "mstar", property = "mstar"), @Result(column = "mlength", property = "mlength"),
		@Result(column = "mcomment", property = "mcomment"),@Result(column = "location", property = "location"),
		@Result(column = "mmassage", property = "mmassage"), 
		@Result(column = "id", property = "movieImgs", many = @Many(select = "com.woniuxy.movice.mapper.MovieImgMapper.findMovieImgByMid")) })
	List<Movie> findMovieByType(Page<Movie> page);

	@Select("select * from movie where id=#{id} and mshow=0")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mname", property = "mname"),
		@Result(column = "director", property = "director"), @Result(column = "mtype", property = "mtype"),
		@Result(column = "mstar", property = "mstar"), @Result(column = "mlength", property = "mlength"),
		@Result(column = "mcomment", property = "mcomment"),@Result(column = "location", property = "location"),
		@Result(column = "mmassage", property = "mmassage"), 
		@Result(column = "id", property = "movieImgs", many = @Many(select = "com.woniuxy.movice.mapper.MovieImgMapper.findMovieImgByMid")) })
	Movie showMovieById(int id);

	@Select("select * from movie where mshow=0 limit 0,10")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mname", property = "mname"),
		@Result(column = "director", property = "director"), @Result(column = "mtype", property = "mtype"),
		@Result(column = "mstar", property = "mstar"), @Result(column = "mlength", property = "mlength"),
		@Result(column = "mcomment", property = "mcomment"),@Result(column = "location", property = "location"),
		@Result(column = "mmassage", property = "mmassage"), 
		@Result(column = "id", property = "movieImgs", many = @Many(select = "com.woniuxy.movice.mapper.MovieImgMapper.findMovieImgByMid")) })
	List<Movie> showTenMovie();

	@Select("select count(*) from movie where mtype like #{mtype} and mshow=0")
	int findMovieNumByType(String mtype);
	
	@Select("select language from movie where id=#{id} and mshow=0")
	String findLanguageByMid(int id);

	@Select("select * from movie where id=#{mid}")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "mname", property = "mname"),
		@Result(column = "director", property = "director"), @Result(column = "mtype", property = "mtype"),
		@Result(column = "mstar", property = "mstar"), @Result(column = "mlength", property = "mlength"),
		@Result(column = "mcomment", property = "mcomment"),@Result(column = "location", property = "location"),
		@Result(column = "mmassage", property = "mmassage"), 
		@Result(column = "id", property = "movieImgs", many = @Many(select = "com.woniuxy.movice.mapper.MovieImgMapper.findMovieImgByMid")) })
	Movie findMovieByMid(Integer mid);

}
